package com.yc.http.tomcat.impl;

import com.yc.http.tomcat.HttpServletRequest;
import com.yc.http.tomcat.HttpServletResponse;
import com.yc.http.tomcat.HttpSession;
import com.yc.http.tomcat.ServletException;

import java.io.IOException;

public class LoginServlet extends HttpServletImpl{

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        if("yc".equals(username) && "123".equals(password)){
            HttpSession session = request.getSession();
            session.setAttribute("myname", username);
            response.sendRedirect("/index.html");
        } else {
            response.sendRedirect("/login.html?loginErr");
        }

    }

    public static void main(String[] args) {
        String a = "Content-Disposition: form-data; name=\"like\"" +
                "" +
                "sing";
        System.out.println("======================");
        System.out.println(a);
        System.out.println("======================");
        String b = a.replaceAll(".+name=\"(.+)\".+","$1");
        System.out.println(b);

//                "\n" +
//                "YC129-刘轩  10:41:33\n" +
//                "                    String keyString = part[1].replaceAll(\"Content-Disposition: form-data; name=\\\"(\\\\w*)\\\"\", \"$1\");\n" +
//                "\n"
    }
}
